package br.com.takashii.lp.web;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.takashii.lp.domain.MensagemDeContato;
import br.com.takashii.lp.util.MailUtil;

@Resource
public class ContatosController {
	
	private final Result result;

	public ContatosController(Result result) {
		this.result = result;
	}
	
	@Get
	@Path("/contatos")
	public void principal() {
		result.forwardTo("/WEB-INF/jsp/contatos/form.jsp");
	}

	@Post
	@Path("/contatos/enviaEmail")
	public void enviaEmail(MensagemDeContato mensagemDeContato) {
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		format.setCalendar(Calendar.getInstance());
		
		String conteudo = 
			"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
			+"<html>"
			+"<head>"
			+"<style>"
			+".titulo{font-family:helvetica, Futura, trajan;color: #B5282E;font-size: 22px;font-style: normal;font-variant: normal;font-weight: bold;height: 26px;padding: 10px;padding-bottom: 0px;}"
			+"label{color:#333;font-size:12px;font-weight: bold;font-variant:normal;font-style:normal;vertical-align:middle;margin:0px;}"
			+"body{font-family:helvetica, futura, trojan;font-size:12px;color: #666;}"
			+"</style>"
			+"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"
			+"<title>Luck Port | mail</title>"
			+"</head>"
			+"<body>"
			+"<div class=\"conteudoCentro\">"
			+"<h3 class=\"titulo\"> Mensagem </h3>"+
			"<table width=\"600px\" border=\"0\" align=\"center\" >" +
			"<tr>" +
			"<td width=\"124\" colspan=\"2\" height=\"20px\">&nbsp;</td>" +
			"</tr>" +
			"<tr>" +
			"<td >" +
			"<label>Nome :</label>" +
			"</td>" +
			"<td >" +
			mensagemDeContato.getNome()+
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td>" +
			"<label>Empresa :</label>" +
			"</td>" +
			"<td>" +
			mensagemDeContato.getEmpresa() +
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td><label>e-Mail :</label></td> " +
			"<td>" +
			mensagemDeContato.getEmail() +
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td><label>Telefone :</label></td>" +
			"<td>" +
			mensagemDeContato.getTelefone()+
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td><label>Cidade :</label></td>" +
			"<td>" +
			mensagemDeContato.getCidade()+
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td><label>Estado :</label></td>" +
			"<td>" +
			mensagemDeContato.getEstado() +
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td><label>Assunto :</label></td>" +
			mensagemDeContato.getAssunto().getDescricao()+
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td colspan=\"2\"><label>Mensagem:\"</label>\"</td>" +        
			"</tr>" +
			"<tr>" +
			"<td colspan=\"2\" height=\"500\">" +
			mensagemDeContato.getConteudo() +
			"</td>" +
			"</tr>" +
			"<tr>" +
			"<td width=\"124\" colspan=\"2\" height=\"20px\">&nbsp;</td>" +
			"</tr>" +
			"</table>"
			+"</div>"
			+"</body>"
			+"</html>";
		
		
		MailUtil mailUtil = new MailUtil();
		mailUtil.sendMimeMail("Contato - mail", conteudo);
	}
	
}
